package wang.aweb.childcar.controller.agentApi;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import wang.aweb.childcar.common.ApiRestResponse;
import wang.aweb.childcar.filter.AgentFilter;
import wang.aweb.childcar.model.pojo.WqPage;
import wang.aweb.childcar.model.query.DeviceParam;
import wang.aweb.childcar.service.DeviceService;

import java.util.Map;

@RestController
@RequestMapping("/agentApi/device/")
public class AgentDeviceController {
    @Autowired
    private DeviceService deviceService;
    @PostMapping("getDeviceList")
    public ApiRestResponse getDeviceList(@RequestBody DeviceParam deviceParam){
        deviceParam.setAgentId(AgentFilter.agentThreadLocal.get().getId());
        PageInfo pageInfo=deviceService.getList(deviceParam.getPage(),deviceParam.getLimit(),deviceParam);
        WqPage wqPage=new WqPage(pageInfo.getTotal(),pageInfo.getList());
        return ApiRestResponse.success(wqPage);
    }
    @PostMapping("disableorEnable")
    public ApiRestResponse disableOrEnable(@RequestBody Map map){
        deviceService.disableOrEnable((Integer) map.get("id"));
        return ApiRestResponse.success();
    }
}
